package cn.webwheel.tutorials.plugin;

import cn.webwheel.Action;
import cn.webwheel.ResultInterpreter;
import cn.webwheel.WebContext;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

public class StringResultInterceptor implements ResultInterpreter<String> {
    public void init() throws Exception {
    }

    public boolean render(String result, WebContext ctx, Action action) throws Exception {
        HttpServletResponse res = ctx.getResponse();
        res.setCharacterEncoding("utf-8");
        res.setContentType("text/html");
        PrintWriter writer = res.getWriter();
        writer.print("<html><body>");
        writer.print("action: " + action + "<br/>");
        writer.print("result: " + result);
        writer.print("</body></html>");
        return true;
    }

    public void destroy() {
    }
}
